<?php

namespace app\common\logic;

/**
 * 我们的业绩逻辑
 */
class OurResult extends LogicBase
{

    /**
     * 获取我们的业绩列表
     */
    public function getOurResultList($where = [], $field = '*', $order = '')
    {
        
        $where[DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelOurResult->getList($where, $field, $order, DB_LIST_ROWS);
    }
    
    
    /**
     * 获取前台我们的业绩列表
     */
    public function getAppOurResultList($where = [], $field = '*', $order = '')
    {
        
        $where[ DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelOurResult->getList($where, $field, $order, 50);
    }
    
    
    
     /**
     * 获取我们的业绩列表
     */
    public function getIndexResultList($where = [], $field = '*', $order = '')
    {
        
        $where[ DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelOurResult->getList($where, $field, $order,13,[],'',13);
    }

    
     /**
     * 我们的业绩编辑
     */
    public function ourResultEdit($data = [])
    {
        
        $validate_result = $this->validateOurResult->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateOurResult->getError()];
        }
        
        $url = url('ourResultList');   
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        if($handle_text == '新增'){
            
            $data['created_at'] = time();
        }
        
        $data['updated_at'] = time();
        
        $result = $this->modelOurResult->setInfo($data);

        $result && action_log($handle_text, '我们的业绩' . $handle_text . '，name：' . $data['result_descrit']);
        
        return $result ? [RESULT_SUCCESS, '我们的业绩操作成功', $url] : [RESULT_ERROR, $this->modelOurResult->getError()];
    }
    
    
    
    /**
     * 企业成就编辑
     */
    public function indexResultEdit($data = [])
    {
        
        $validate_result = $this->validateOurResult->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateOurResult->getError()];
        }
        
        $url = url('home/result');   
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        if($handle_text == '新增'){
            
            $data['created_at'] = time();
        }
        
        $data['is_index'] = 1;
        
        $data['updated_at'] = time();
        
        $result = $this->modelOurResult->setInfo($data);

        $result && action_log($handle_text, '企业成就' . $handle_text . '，name：' . $data['result_descrit']);
        
        return $result ? [RESULT_SUCCESS, '企业成就操作成功', $url] : [RESULT_ERROR, $this->modelOurResult->getError()];
    }
  
    /**
     * 获取我们的业绩信息
     */
    public function getOurResultInfo($where = [], $field = '*')
    {
       
        $where[DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelOurResult->getInfo($where, $field);
    }
    
    /**
     * 获取我们的业绩分类列表
     */
    public function getOurResultCategoryList($where = [], $field = true, $order = '', $paginate = 0)
    {
        return $this->modelOurResult->getList($where, $field, $order, $paginate);
    }
    
    
    /**
     * 
     */
    public function resultImgEdit($data=[])
    {
        $validate_result = $this->validateResultImg->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateResultImg->getError()];
        }
        
        $url = url('home/resultImg');   
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        if($handle_text == '新增'){
            
            $data['created_at'] = time();
        }
        
        $data['updated_at'] = time();
        
        $data['describe'] = html_entity_decode($data['describe']);
        
        $result = $this->modelResultImg->setInfo($data);

        $result && action_log($handle_text, '成就图片' . $handle_text . '，name：' . $data['describe']);
        
        return $result ? [RESULT_SUCCESS, '成就图片操作成功', $url] : [RESULT_ERROR, $this->modelResultImg->getError()];
    }
    
    
    /**
     * 获取成就图片
     */
    public function getResultImg()
    {
        
        return $this->modelResultImg->getInfo();
    }
}

